<?php
require("../../class/connect.php");
require("../../class/db_sql.php");
require("../../class/q_functions.php");
require("../../class/user.php");
require("../../data/dbcache/class.php");
require("../../data/dbcache/MemberLevel.php");
require("../../class/DownSysFun.php");
$link=db_connect();
$empire=new mysqlquery();
$editor=1;
$ecmsreurl=2;
$id=(int)$_GET['id'];
$pathid=(int)$_GET['pathid'];
$classid=(int)$_GET['classid'];

//扣點函數
function ViewOnlineKFen($showdown_r,$u,$userid,$classid,$id,$pathid,$r){
	global $user_tablename,$level_r,$user_group,$user_userid,$class_r,$dbtbpre,$public_r,$user_userdate,$user_userfen,$user_username,$empire,$have_bak,$have_fen;
	if($showdown_r[2])
	{
		//下載次數限制
		$setuserday="";
		if($level_r[$u[$user_group]][daydown])
		{
			$setuserday=DoCheckMDownNum($userid,$u[$user_group],1);
		}
		//點數是否足夠
		$showdown_r[3]=intval($showdown_r[3]);
		if($showdown_r[3])
		{
			if($have_fen==1)
			{
				//去除點數
				$usql=$empire->query("update ".$user_tablename." set ".$user_userfen."=".$user_userfen."-".$showdown_r[3]." where ".$user_userid."='$userid'");
			}
			if($have_bak==0)
			{
				//備份下載記錄
				$utfusername=doUtfAndGbk($u[$user_username],1);
				BakDown($classid,$id,$pathid,$userid,$utfusername,$r[title],$showdown_r[3],1);
			}
		}
		//更新用戶下載次數
		if($setuserday)
		{
			$usql=$empire->query($setuserday);
		}
	}
	//總下載數據增一
    $usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set totaldown=totaldown+1 where id='$id'");
}

/*
來源識別
if(!strstr($_SERVER['HTTP_REFERER'],$public_r[newsurl]))
{
	exit();
}
*/
if(!$classid||empty($class_r[$classid][tbname])||!$id)
{
	echo"<script>alert('Это видео не существует ');window.close();</script>";
	exit();
}
$mid=$class_r[$classid][modid];
$tbname=$class_r[$classid][tbname];
$query="select * from {$dbtbpre}ecms_".$tbname." where id='$id' and classid='$classid'";
$r=$empire->fetch1($query);
if(!$r[id])
{
	echo"<script>alert('Это видео не существует ');window.close();</script>";
	exit();
}
//副表
if($emod_r[$mid]['tbdataf']&&$emod_r[$mid]['tbdataf']<>',')
{
	$selectdataf=substr($emod_r[$mid]['tbdataf'],1,-1);
	$finfor=$empire->fetch1("select ".$selectdataf." from {$dbtbpre}ecms_".$tbname."_data_".$r[stb]." where id='$r[id]'");
	$r=array_merge($r,$finfor);
}
//區分下載地址
$path_r=explode("\r\n",$r[onlinepath]);
if(!$path_r[$pathid])
{
	echo"<script>alert('Это видео не существует ');window.close();</script>";
	exit();
}
$showdown_r=explode("::::::",$path_r[$pathid]);
//下載權限
$downgroup=$showdown_r[2];
if($downgroup)
{
	$user=islogin();
	//取得會員資料
	$u=$empire->fetch1("select * from ".$user_tablename." where ".$user_userid."='$user[userid]' and ".$user_rnd."='$user[rnd]' limit 1");
	if(empty($u[$user_userid]))
	{
		echo"<script>alert('Же счет, только одна линия ');window.close();</script>";
        exit();
    }
	//下載次數限制
	if($level_r[$u[$user_group]][daydown])
	{
		$setuserday=DoCheckMDownNum($user[userid],$u[$user_group],2);
		if($setuserday=='error')
		{
			echo"<script>alert('Скачать и посмотреть ваш система ограничивает число имеет больше, чем (".$level_r[$u[$user_group]][daydown]." Times )!');window.close();</script>";
			exit();
		}
	}
	if($level_r[$downgroup][level]>$level_r[$u[$user_group]][level])
	{
		echo"<script>alert('Ваш уровень членства менее (".$level_r[$downgroup][groupname].")，Нет разрешения на просмотр этого видео! ');window.close();</script>";
            exit();
	}
	//點數是否足夠
	$have_bak=0;
	$have_fen=0;
	if($showdown_r[3])
	{
		//---------是否有歷史記錄
			$bakr=$empire->fetch1("select id,truetime from {$dbtbpre}enewsdownrecord where id='$id' and classid='$classid' and userid='$user[userid]' and pathid='$pathid' and online=1 order by truetime desc limit 1");
			if($bakr[id]&&(time()-$bakr[truetime]<=$public_r[redodown]*3600))
			{
				$have_bak=1;
			}
			else
			{
				//包月卡
				if($u[$user_userdate]-time()>0)
				{}
				//點數
				else
				{
			       if($showdown_r[3]>$u[$user_userfen])
			       {
					echo"<script>alert('Пункта меньше, чем ваши  $showdown_r[3] Точка, не могу смотреть это видео ');window.close();</script>";
					exit();
			       }
				   $have_fen=1;
				}
			}
	}
}
//驗證碼
$ip=egetip();
$pass=md5(ReturnDownSysCheckIp()."wm_chief".$public_r[downpass].$user[userid]);
$op=GetOnlinePass();
$url="../../enews/?enews=GetSofturl&classid=$classid&id=$id&pathid=$pathid&pass=".$pass."&p=".$user[userid].":::".$user[rnd]."&onlinetime=".$op[0]."&onlinepass=".$op[1];
$trueurl=ReturnDSofturl($showdown_r[1],$showdown_r[4],'../../',0);//實際地址
$playerpass="wm_chief";
//自動識別播放器
if(empty($r[playerid]))
{
	$ftype=GetFiletype($showdown_r[1]);
	if($ftype=='.swf')
	{
		@include("flasher.php");
	}
	elseif($ftype=='.flv')
	{
		@include("flver.php");
	}
	elseif(strstr($realplayertype,','.$ftype.','))
	{
		@include("realplayer.php");
	}
	else
	{
		@include("mediaplayer.php");
	}
}
else
{
	$playerr=$empire->fetch1("select filename from {$dbtbpre}enewsplayer where id='$r[playerid]'");
	if($playerr['filename'])
	{
		@include($playerr[filename]);
	}
}
db_close();
$empire=null;
?>